package com.luckmgr.init;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.common.constant.SystemConstant;

public class LoginInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
        // 不过滤的uri   
        String[] notFilter = new String[] {"login","loginindex","index/out","login.jsp", "error.jsp"};  
  
        // 请求的uri   
        String uri = request.getRequestURI();  
        System.out.println(uri);
        // uri中包含background时才进行过滤   
        for (String s : notFilter) {  
            if (uri.indexOf(s) != -1) {  
                // 如果uri中包含不过滤的uri，则不进行过滤   
            	return super.preHandle(request, response, handler);
            }  
        }
        //拦截
        HttpSession session = request.getSession();
        if(null==session.getAttribute(SystemConstant.ESSIONUSER)){
        	response.sendRedirect(request.getContextPath()+"/index/out");
            return false;
        }
        
        //这里做权限 bobo
		/*User user = userServices.userLogin(loginMap("test2@163.com","123456"));
		user.setP_accountno_id(3);*/
		return super.preHandle(request, response, handler);
	}
	
	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		super.postHandle(request, response, handler, modelAndView);
	}
	
	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		super.afterCompletion(request, response, handler, ex);
	}
	
	
	
}
